package com.company.servicename.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author fangsong.zhang
 * @date 2019/9/27 15:28
 * Copyright zfs
 * 类说明:多线程工具
 */
public class ThreadUtil {
    /**
     * 获取一个默认的线程池
     *
     * @return 默认线程池
     */
    public static ThreadPoolExecutor getDefaultPool() {
        int poolSize = 12;
        int maxPoolSize = 128;
        long aliveTime = 15;
        ArrayBlockingQueue queue = new ArrayBlockingQueue(2048);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize, maxPoolSize, aliveTime, TimeUnit.SECONDS, queue);
        return executor;
    }

    /**
     * 获取一个大号的线程池
     *
     * @return 线程池
     */
    public static ThreadPoolExecutor getLargePool() {
        int poolSize = 12;
        int maxPoolSize = 128;
        long aliveTime = 60;
        ArrayBlockingQueue queue = new ArrayBlockingQueue(100*100*10);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize, maxPoolSize, aliveTime, TimeUnit.SECONDS, queue);
        return executor;
    }
}
